package lg.minecraft.plugin.worldprotect.config;

import lg.minecraft.plugin.library.config.LGBaseConfig;
import lg.minecraft.plugin.worldprotect.LGWorldProtect;
import lg.minecraft.plugin.worldprotect.WorldSettingType;
import lombok.Getter;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * @author langle__
 * @version 1.0
 */
@Getter
public class MainConfig extends LGBaseConfig {

    private final Map<WorldSettingType, Material> icons = new HashMap<>();
    private final Set<Material> containers = new HashSet<>();

    private boolean enableTip;

    public MainConfig() {
        super(LGWorldProtect.getInstance(), "config");
        this.init();
    }

    @Override
    public void load() {
        super.load();
        this.icons.clear();
        this.containers.clear();
        ConfigurationSection section = this.getConfigurationSection("icon");
        if (section != null) {
            for (String key : section.getKeys(false)) {
                String value = section.getString(key);
                if (value == null) continue;
                String name = key.toUpperCase();
                WorldSettingType setting = WorldSettingType.getValue(name);
                if (setting == null) continue;
                Material material = Material.matchMaterial(value);
                if (material == null) material = Material.STONE;
                icons.put(setting, material);
            }
        }
        this.getStringList("container").forEach(name -> containers.add(Material.getMaterial(name)));
        this.enableTip = this.getBoolean("enable.tip");
    }

}
